﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FazaDemo.BL.Factories;
using FazaDemo.BL.InterfaceDomain;
using FazaDemo.BL.Services_;
using FazaDemo.BL.SubDomains;

namespace FazaDemo.BL.Services_
{
    class NavCondParser
    {

        private readonly InfoListsProvider _listsProvider;

        private readonly ParamsProvider _paramsProvider;

        private readonly INavCondElemFactory _factory;

        private readonly NavElementsDistincter _distincter;

        public NavCondParser()
        {
            _listsProvider = new InfoListsProvider();
            _paramsProvider = new ParamsProvider();
            _factory = new NavCondElemFactory();
            _distincter = new NavElementsDistincter();
        }

        public IList<NavCondElement> GenerateNavCondElems(string ecqText)
        {
            string curText = ecqText;
            IList<List<string>> fieldsInfoLists = _listsProvider.GetInfoLists(curText);
            IList<NavCondElement> navElements = new List<NavCondElement>();
            foreach (var fieldsInfo in fieldsInfoLists)
            {
                var curInfo = fieldsInfo;
                IList<string> fieldParams = _paramsProvider.GetParams(curInfo);
                var navElement = _factory.GetNavCondElement(fieldParams);
                navElements.Add(navElement);
                navElements = _distincter.Resolve(navElements);
            }
            return navElements;
        }

    }
}
